package com.goodving.guli.activity;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.goodving.guli.R;

/**
 * Created by john on 2015/11/26.
 */
public class SystemBarTintActivity extends BaseActivity {
    private View mContentView;
    private boolean mDisableStatusBarTintAuto;
    private ff mSystemBarTintManager;

    public void applyStatusBarTint(int i) {
        if (!C3246a.m22924b(this)) {
            return;
        }
        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setNavigationBarColor(i);
            if (C1757t.m13469b(this)) {
                i = Color.rgb((int) (((double) Color.red(i)) * 0.75d), (int) (((double) Color.green(i)) * 0.75d), (int) (((double) Color.blue(i)) * 0.75d));
            }
            getWindow().setStatusBarColor(i);
            return;
        }
        this.mSystemBarTintManager.m14853a(i);
    }

    class fe implements Runnable {
        final /* synthetic */ SystemBarTintActivity f10210a;

        fe(SystemBarTintActivity systemBarTintActivity) {
            this.f10210a = systemBarTintActivity;
        }

        public void run() {
            int i = 0;
            if (!this.f10210a.mDisableStatusBarTintAuto) {
                try {
                    this.f10210a.mContentView.buildDrawingCache();
                    Bitmap drawingCache = this.f10210a.mContentView.getDrawingCache();
                    if (Build.VERSION.SDK_INT <= 19) {
                        i = this.f10210a.mSystemBarTintManager.m14851a().m14876b();
                    }
                    i = drawingCache.getPixel(0, i);
                    this.f10210a.mContentView.destroyDrawingCache();
                    this.f10210a.applyStatusBarTint(i);
                } catch (Exception e) {
                    this.f10210a.applyStatusBarTint(R.color.bg_color_grey);
                    e.printStackTrace();
                }
            }
        }
    }

    public void applyStatusBarTintAuto() {
        if (C3246a.m22924b(this) && this.mContentView != null) {
            this.mContentView.post(new fe(this));
        }
    }

    public void applyStatusBarTintRes(int i) {
        applyStatusBarTint(getResources().getColor(i));
    }

    public void applyStatusBarTintResDrawable(int i) {
        if (!C3246a.m22924b(this)) {
            return;
        }
        if (Build.VERSION.SDK_INT >= 21) {
            this.mDisableStatusBarTintAuto = false;
            applyStatusBarTintAuto();
            return;
        }
        this.mSystemBarTintManager.m14857b(i);
    }

    public void configStatusBarTint() {
        if (C3246a.m22924b(this)) {
            this.mContentView = findViewById(android.R.id.content);
            this.mSystemBarTintManager = new ff(this);
            if (Build.VERSION.SDK_INT < 21) {
                this.mSystemBarTintManager.m14855a(true);
            }
        }
    }

    public void disableAutoApplyStatusBarTint() {
        this.mDisableStatusBarTintAuto = true;
    }

    public int getStatusBarHeight() {
        if (this.mSystemBarTintManager == null) {
            return 0;
        }
        fh a = this.mSystemBarTintManager.m14851a();
        return a != null ? a.m14876b() : 0;
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (C3246a.m22924b(this) && Build.VERSION.SDK_INT <= 19) {
            setTheme(R.style.MyTheme);
        }
        configStatusBarTint();
        applyStatusBarTintAuto();
    }
}





